package com.example.jpatest.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.*;

/**
 * 获奖实体类
 * @author czx
 */

@Entity
@Data
@ToString(exclude = {"enter","reward"})
@EqualsAndHashCode(exclude = {"enter","reward"})
public class Win {
    public static enum WinLevel{
        /**
         * 金牌
         */
        GOLD,
        /**
         * 银牌
         */
        SILVER,
        /**
         * 铜牌
         */
        COPPER,
        /**
         * 特等奖
         */
        GRAND,
        /**
         * 一等奖
         */
        FIRST,
        /**
         * 二等奖
         */
        SECOND,
        /**
         * 三等奖
         */
        THIRD
    }

    /**
     * 获奖id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 奖金
     */
    private int prize;

    /**
     * 获奖级别
     */
    @Enumerated(EnumType.ORDINAL)
    private WinLevel winLevel;

    /**
     * 对应的报名
     */
    @OneToOne(mappedBy = "win",cascade = {CascadeType.REFRESH,CascadeType.MERGE})
    private Enter enter;

    /**
     * 奖励
     */
    @OneToMany(mappedBy = "win")
    @JsonIgnore
    private Set<Reward> reward = new HashSet<>();
}
